* import the downloaded Compustat file
clear

import delimited "input\compannual.csv"
* check and remove duplicates by permno-fyear
quietly bys lpermno fyear:  gen dup = cond(_N==1,0,_n)
drop if dup>0 & linkprim=="C"
duplicates drop lpermno fyear, force
save "comp_ann.dta", replace

* import patent data from KPSS
clear
import delimited "input\firm_innovation.csv"
save "patents.dta", replace